<?php

/**
 * @author tungck
 * @filesource staff_managers_model.php
 * file model for process staff manager
 */
?>

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class order_model extends CI_Model {

    public $tableName = 'datcom';

    function order_model() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->database();
    }

    // lay danh sách dat com
    function getList($data) {
        $recordCount = $this->db->count_all_results('datcom');
        $query = $this->db->query("SELECT * FROM datcom ORDER BY " . $data['sort'] . " LIMIT " . $data['startIndex'] . "," . $data['pageSize'] . ";");
//        $query = $this->db->query("SELECT * FROM datcom  ");
        if ($query) {
            $result['query'] = $query->result();
            $result['recordCount'] = $recordCount;
            return $result;
        } else {
            return false;
        }
    }

    public function getDetailOrderDay($id) {

        $query = $this->db->query(" select hosonhanvien.MaHoSo, hosonhanvien.HoTen, hosonhanvien.SoDienThoai from datcom, datcomnhanvien, hosonhanvien where hosonhanvien.MaHoSo=datcomnhanvien.MaHoSo and datcom.MaNgayDatCom = datcomnhanvien.MaNgayDatCom and datcom.MaNgayDatCom= '$id'");
        if ($query) {
            return $query->result();
        } else {
            return false;
        }
    }

    public function getDay($id) {

        $query = $this->db->query("select NgayDatCom from datcom where MaNgayDatCom = '$id'");
        if ($query) {
            return $query->result();
        } else {
            return false;
        }
    }

    function insertDay($data) {
        $this->db->insert('datcom', $data);
        $query = $this->db->get_where('datcom', 'MaNgayDatCom = LAST_INSERT_ID()');
        if ($query) {
            return $query->result();
        } else {
            return false;
        }
    }

    function deleteDay1($id) {
        $this->db->delete('datcom', array('MaNgayDatCom' => $id));
    }

    
     function updateDay1($data){
        $this->db->where('MaNgayDatCom', $data['MaNgayDatCom']);
        $this->db->update('datcom', $data); 
    }
    
    
      function file_xls_md($tt ) {
        $tt1=$tt;
//        $que=$this->input->get('query');
        $iid = $this->input->get('id');
         $this->load->helper('date');
        //////////////////////////////////////////
       
//         $dayId = $this->input->get('dayId');
        if ($iid !== false) {

            $this->load->helper('url');
            $this->load->library(array('form_validation', 'session'));
          
//            $this->load->model("order_model");
//            $result = $this->order_model->getDetailOrderDay($iid);
//            $data['query'] = $this->order_model->getDetailOrderDay($iid);
        }
        ////////////////////////////////////////////////////////////

        $this->load->library('phpexcel/PHPExcel');

        $sheet = $this->phpexcel->getActiveSheet();
        $sheet->getColumnDimension('A')->setWidth(5);
        $sheet->setCellValue('A' . '1', $tt1);
        $sheet->setCellValue('A2', 'Danh sách');
        
        
//        
//        foreach($query as $row){
// 
//          $sheet->setCellValue('C3', $row->MaHoSo);
//         
//            }
//  
        

        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
        header('Content-type: application/vnd.ms-excel');
        $writer->save('php://output');
    }
    
}
?>